/**
 *             _..--""-.                  .-""--.._
           _.-'         \ __...----...__ /         '-._
         .'      .:::...,'              ',...:::.      '.
        (     .'``'''::;                  ;::'''``'.     )
         \             '-)              (-'             /
          \             /                \             /
           \          .'.-.            .-.'.          /
            \         | \0|            |0/ |         /
            |          \  |   .-==-.   |  /          |
             \          `/`;          ;`\`          /
              '.._      (_ |  .-==-.  | _)      _..'
                  `"`"-`/ `/'        '\` \`-"`"`
                       / /`;   .==.   ;`\ \
                 .---./_/   \  .==.  /   \ \
                / '.    `-.__)       |    `"
               | =(`-.        '==.   ;
                \  '. `-.           /
                 \_:_)   `"--.....-'

                 file: gripper_node.h
                 description: node handle to determine when to close the gripper and with how much force.
                 authors: Michiel and Peter
 */
#ifndef GRIPPER_NODE_H__
#define GRIPPER_NODE_H__

#include <ros/ros.h>
#include <std_msgs/Int32.h>
#include <std_msgs/Float32.h>
#include "gripper.h"
#include "gripper_defines.h"
#include "topics.h"

/**
 * Node to control the gripper.
 */
class GripperNode
{
protected:
	ros::NodeHandle nh_;
	ros::Subscriber motor_sub_;
	ros::Publisher current_pub_;

	int state_;		// current state of the gripper
	Gripper motor_;
	ros::Time timestamp_;
public:
	/**
	 * MotorNode constructor.
	 */
	GripperNode() : state_(GripperDefines::OPEN)
	{
	}

	/**
	 * GripperNode destructor.
	 */
	~GripperNode()
	{
		nh_.shutdown();
	}

	/**
	 * Init motor, subscribe to sensor.
	 */
	void init();

	/**
	 * Publish current data and control the current.
	 */
	void spin();

	/**
	 * Publish current data.
	 */
	void publishCurrent();

	/**
	 * Open or close motor.
	 * @param	Int32	OPEN, CLOSED.
	 */
	void motorCallback(const std_msgs::Int32::ConstPtr &open);
};

#endif
